package ali;

import ali.entities.Something;
import ali.point.Point;
import com.googlecode.totallylazy.Predicate;
import com.googlecode.totallylazy.Sequence;
import com.googlecode.totallylazy.Sequences;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: aliolci
 * Date: 20/05/11
 * Time: 21:14
 * To change this template use File | Settings | File Templates.
 */
public abstract class World {
    Sequence<? extends Something> entitiesOnTheWorld = Sequences.empty();

    public abstract Point getSize();

    private List <Object> everythingInTheWorld = new ArrayList<Object>();

    public Sequence<? extends Something> getSomethingWhichAreUnderThisPoint(final Point thisPoint, final Float tolerance){
    return entitiesOnTheWorld.filter(onThemWhichHave(thisPoint, tolerance));
    }

    private Predicate<Something> onThemWhichHave(final Point thisPoint, final Float tolerance) {
        return new Predicate<Something>() {
            public boolean matches(Something somethingMoving) {
                return somethingMoving.isOnIt(thisPoint,tolerance);
            }
        };
    }

    public void addSomethingToTheWorld(Object o){
        this.everythingInTheWorld.add(o);
    }
    public void removeSomethingFromTheWorld(Object o){
        this.everythingInTheWorld.remove(o);
    }
}
